import axios from 'axios';
import config from "@/config";
import {getToken} from "@/utils/index";
// import {message} from "ant-design-vue";

export default function ({url='',method='',data={},fullUrl}) {
  return new Promise((resolve, reject)=>{
    let obj={
      url:fullUrl? fullUrl : config.baseUrl + url,
      method:method.toLowerCase(),
      headers:{
        Authorization:'Bearer '+getToken()
      }
    }
    if(method.toLowerCase()==='get'){
      obj.params=data
    }else {
      obj.data=data
    }
    axios(obj).then((res) => {
      console.log('%c'+method+' %c'+url,'color: blue;','color: green;',data,'=>',res.data)
      resolve(res.data)
    }).catch((err) => {
      console.log('%c失败 '+url,'color: red;',data,'=>',err)
      reject()
      // message.error(err.response?.data?.msg||'系统错误')
    })
  })
}
